//
//  YBApiManager+Chat.m
//  ChangChat
//
//  Created by Cocoa on 2019/9/3.
//  Copyright © 2019 yibai. All rights reserved.
//

#import "YBApiManager+Chat.h"

@implementation YBApiManager (Chat)

- (RACSignal *)sendMsgWithContent:(NSString *)content client_id:(NSString *)client_id group_id:(NSString *)group_id type:(NSString *)type s_image:(NSString *)s_image second:(NSInteger)second file_name:(NSString *)file_name file_size:(NSString *)file_size {
    NSMutableDictionary *m_param = [NSMutableDictionary dictionary];
    if (content.isHaveStr) {
        m_param[@"content"] = content;
    }
    m_param[@"client_id"] = client_id;
    m_param[@"group_id"] = group_id;
    m_param[@"type"] = type;
    if (s_image.isHaveStr) {
        m_param[@"s_image"] = s_image;
    }
    if (second > 0) {
        m_param[@"second"] = @(second);
    }
    if (file_name.isHaveStr) {
        m_param[@"file_name"] = file_name;
    }
    if (file_size.isHaveStr == YES) {
        m_param[@"file_size"] = file_size;
    }
    
    return [self sendPostRequest:@"index/send_message" param:m_param];
}

- (RACSignal *)sendReceivedMsgWithMsgId:(NSString *)msgId {
    NSDictionary *param = @{@"message_id": msgId};
    return [self sendGetRequest:@"index/accept" param:param];
}

- (RACSignal *)sendReadedMsgWithGroupId:(NSString *)group_id {
    NSDictionary *param = @{@"group_id": group_id};
    return [self sendGetRequest:@"index/read" param:param];
}

- (RACSignal *)recallMsgWithMsgId:(NSInteger)group_logs_id {
    NSDictionary *param = @{@"group_logs_id": @(group_logs_id)};
    return [self sendGetRequest:@"index/reset_msg" param:param];
}


- (RACSignal *)createGroupChatWithGroupUserIds:(NSString *)groupUids {
    NSDictionary *param = @{@"user_ids": groupUids};
    return [self sendGetRequest:@"group/new_group" param:param];
}
- (RACSignal *)groupInfoWithGroupId:(NSString *)group_id {
    NSDictionary *param = @{@"group_id": group_id};
    return [self sendGetRequest:@"group/search_group" param:param];
}

- (RACSignal *)getGroupChatList {
    
    return [self sendGetRequest:@"group/my_groups" param:@{}];
}

- (RACSignal *)getGroupAllUserWithGroupId:(NSString *)group_id {
    NSDictionary *param = @{@"group_id": group_id};
    return [self sendGetRequest:@"group/getuserlist" param:param];
}

- (RACSignal *)updateGroupWithGroupId:(NSString *)group_id nickName:(NSString *_Nullable)nickname no_disturb:(NSString *)no_disturb {
    NSMutableDictionary *param = [NSMutableDictionary dictionaryWithObject:group_id forKey:@"group_id"];
    if (nickname != nil) {
        [param setObject:nickname forKey:@"nickname"];
    }
    if (no_disturb.isHaveStr) {
        [param setObject:no_disturb forKey:@"no_disturb"];
    }
    return [self sendGetRequest:@"group/change_in_group" param:param];
}

- (RACSignal *)deleteGroupUserWithUserIds:(NSString *)user_ids groupId:(NSString *)group_id {
    NSDictionary *param = @{@"group_id": group_id,
                            @"user_ids": user_ids
                            };
    return [self sendGetRequest:@"group/del_group_user" param:param];
}
- (RACSignal *)addGroupUserWithUserIds:(NSString *)user_ids groupId:(NSString *)group_id {
    NSDictionary *param = @{@"group_id": group_id,
                            @"user_ids": user_ids
                            };
    return [self sendGetRequest:@"group/to_group" param:param];
}
- (RACSignal *)dismissGroupWithGroupId:(NSString *)group_id {
    NSDictionary *param = @{@"group_id": group_id};
    return [self sendGetRequest:@"group/del_group" param:param];
}
- (RACSignal *)updateGroupName:(NSString *)groupName groupAvatar:(NSString *)group_avatar group_id:(NSString *)group_id {
    NSMutableDictionary *param = [NSMutableDictionary dictionaryWithObject:group_id forKey:@"group_id"];
    if (groupName.isHaveStr == YES) {
        [param setObject:groupName forKey:@"group_name"];
    }
    if (group_avatar.isHaveStr == YES) {
        [param setObject:group_avatar forKey:@"group_avatar"];
    }
    return [self sendGetRequest:@"group/update_group_data" param:param];
}
- (RACSignal *)quitGroupWithgroup_id:(NSString *)group_id {
    NSDictionary *param = @{@"group_id": group_id};
    return [self sendGetRequest:@"group/leavegroup" param:param];
}
- (RACSignal *)groupDisableSendMsgWithGroupId:(NSString *)group_id {
    NSDictionary *param = @{@"group_id": group_id};
    return [self sendGetRequest:@"group/shutupwithall" param:param];
}
- (RACSignal *)groupEnableSendMsgWithGroupId:(NSString *)group_id {
    NSDictionary *param = @{@"group_id": group_id};
    return [self sendGetRequest:@"group/noshutupwithall" param:param];
}
@end
